package com.huluobo.a2107monthdemo.category

import androidx.lifecycle.MutableLiveData
import com.huluobo.a2107monthdemo.base.BaseRepo
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlin.math.sign

/**
 *  Created by LC on 2023/12/4.
 */
class CategoryRepo : BaseRepo() {
    fun getCategory(success: MutableLiveData<CategoryBeanResult>, failed: MutableLiveData<String>) {
        getService().getCategory()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<CategoryBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: CategoryBeanResult) {
                    success.value = t
                }
            })
    }

    fun getCategoryGoodsList(
        categoryId: Int,
        currentPage: Int,
        pageSize: Int,
        success: MutableLiveData<CategoryGoodsListBeanResult>,
        failed: MutableLiveData<String>
    ) {
        getService().getCategoryGoodsList(categoryId, currentPage, pageSize)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<CategoryGoodsListBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: CategoryGoodsListBeanResult) {
                    success.value = t
                }
            })
    }
}